package me.winds.wrapper.base.presenter;

import java.lang.reflect.ParameterizedType;

/**
 * Author:  winds
 * Email:   heardown@163.com
 * Date:    2019/5/26.
 * Desc:
 */
public class PresenterFactory {

    public static  <T extends Presenter> T createPresenter(Class<T> clazz) {
        T presenter = null;
        ParameterizedType type = (ParameterizedType) clazz.getGenericSuperclass();
        Class<? extends MvpPresenter> presenterClass = (Class<? extends MvpPresenter>) type.getActualTypeArguments()[0];
        try {
            presenter = (T) presenterClass.newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return presenter;
    }
}
